package com.event.demo.event.annotation;

import com.event.demo.event.CustomEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * 事件监听者[注解方式]
 */
@Component
public class CustomEventListenerAnnotationSecond {
    @EventListener(CustomEvent.class)
    public void myEventListener(CustomEvent customEvent) {
        System.out.println(LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")) +
                " [Annotation 注解式]接收到事件内容2：" +
                customEvent.getMessage());
    }
}
